package database;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import databaseInterface.CustomerManageInterface;
import databaseInterface.StrategyManageInterface;

import po.StrategyPO;

public class StrategyManage implements StrategyManageInterface{

		Statement stmt;
		DatabaseConnection db= new DatabaseConnection();
		
		public   void connect (){
	        
	         stmt =db.connect();
	    }
	    
		public void insert (StrategyPO  s){
	   	 String insert ="insert into  strategy (pointToMoneyRate,moneyToPointRate,maxUseScale) values ("+s.getPointToMoneyRate()+","+s.getMoneyToPointRate()+","+s.getMaxUseScale()+")";
	        try {
				stmt.executeUpdate(insert);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	   
	  }
	  
	   
		public void update (StrategyPO s){
	    	
	    	String update ="update strategy set pointToMoneyRate= "+ s.getPointToMoneyRate()+", moneyToPointRate = "+s.getMoneyToPointRate()+", maxUseScale ="+s.getMaxUseScale() ;
	        try {
				stmt.executeUpdate(update);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}    
	    }
	    
		public StrategyPO query (){
	    	String query = "select * from strategy  ";
	    	StrategyPO s = new StrategyPO ();
	     	try {
				ResultSet rs= stmt.executeQuery(query);
				rs.next();
		        s.setPointToMoneyRate(rs.getDouble(2));
		        s.setMoneyToPointRate(rs.getDouble(3));
		        s.setMaxUseScale(rs.getDouble(4));
	    	
	    	} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    	
	    	return s;	
	    }
	   
		public void close(){
		      db.close();
		    }
		   
	
	    
	    
	

}
